<template>
    <view class="subassembly_goods">
        <view class="goods_part" v-for="(item, i) in list" :key="i" :class="{'showBlock': list.length === 2 }">
            <view class="goods_label">{{item.type}}</view>
            <view class="goods_picture" >
				<image id="img" :src="item.img" mode="widthFix" @click="toPage(item,index)"></image>	
            </view>
            <view class="goods_text">
                <p @click="toPage(item,index)">{{item.title}}</p>
                <span>已兑{{ item.exchange }}件</span>
            </view>
            <view class="goods_num">
                <p>{{ item.score }}积分</p>
				<image src="/static/img/add.png"   @click="show_specification"></image>
            </view>
        </view>
		<!-- 选择规格 -->
		<specification-popup ref="specificationPopup" @close="close"></specification-popup>
    </view>
</template>
<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	import mixins from '@/common/mixins.js';
export default {
	mixins:[mixins],
    props: {
        goods_data: {
            type: Array,
            default: ()=>[],
        },
    },
    components: {
		
	},
    data() {
        return {
            
		};
    },
	watch: {
	},
    computed: {
		list() {
			let arr = this.newgoods(this.goods_data);
			return arr ;
		},
	},
    methods: {
		// 重新排序数组     原先数组[1,2,3,4,5,6]    排序后[1,3,5,2,4,6]
        newgoods(list) {
            if (list && list.length > 0 && list.length != 2) {
                let total = { 0: [], 1: [], length: 2 };
                list.forEach((item, index) => {
                    total[index % 2].push(item);
                });
                const newList = [].concat(...Array.from(total));
                return newList;
            }
			if (list.length == 2) {
				return list;
			}
        },
		// 页面跳转
		toPage(item,index){
			this.$store.dispatch('init/get_product', item)
			uni.navigateTo({
				url: "/pages/goods/detail/index" + "?name=" + item.id + item.name
			})
		},
		// 点击选择一栏，弹出对应弹窗
		show_specification() {
			this.$refs.specificationPopup._data.show = true
		},
    },
    beforeCreate() {},
    created() {},
    beforeMount() {},
    mounted() {
	},
    beforeUpdate() {},
    updated() {},
    beforeDestroy() {},
    destroyed() {},
};
</script>
<style scoped lang='scss'>
@import "./index.scss";
.showBlock:nth-child(2) {
	display: block!important;
}
</style>